package com.zzyy.study;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.concurrent.DelayQueue;

/**
 * @auther zzyy
 * @create 2024-07-06 17:46
 */
public class ComparableDemo
{
    public static void main(String[] args)
    {
        Book book1 = new Book(1, "java", 100d);
        Book book2 = new Book(2, "mysql", 13d);
        Book book3 = new Book(3, "flink", 253d);

        Book[] books = {book1, book2, book3};

        for (Book book : books) {
            System.out.println(book);
        }

        Arrays.sort(books);
        System.out.println(Arrays.toString(books));

    }
}



@AllArgsConstructor
@NoArgsConstructor
@Data
class Book implements Comparable<Book>
{
    private Integer id;
    private String bookName;
    private double bookPrice;


    public int compareTo(Book o)
    {
        if(this.bookPrice > o.getBookPrice()){
            return 1;
        }else if(this.bookPrice < o.getBookPrice()){
            return -1;
        }else {
            return 0;
        }
    }
}